package netty.io.demo.RPC.client;

import netty.io.demo.RPC.utils.Constants;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

public class NettyClient {
  private static ObjectOutputStream out;

//  public static void main(String[] args) {
//    try {
//      Socket socket = new Socket();
//      socket.connect(new InetSocketAddress(Constants.ADDRESS, Constants.PORT));
//
//      out = new ObjectOutputStream(socket.getOutputStream());
//
//      System.out.println("client startup success ...");
//
//      while (true) {
//      }
//    } catch (IOException e) {
//      throw new RuntimeException(e);
//    }
//  }
  
  /**
   * 从这里发送消息
   *
   * @param bytes 表示字节大小
   * @author lihh
   */
  public static void sendMessage(byte[] bytes) {
    try {
      Socket socket = new Socket();
      socket.connect(new InetSocketAddress(Constants.ADDRESS, Constants.PORT));
      
      out = new ObjectOutputStream(socket.getOutputStream());
      
      System.out.println("client startup success ...");
      out.write(bytes);
      
      while (true) {
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}
